<?php #20070423 http://www.framework.altervista.org/FrameWork/applications/Headlines/FlatNuke/application.inc

/*****************/

$rss_file="http://127.0.0.1/flatnuke-2.5.9/misc/backend.xml";
$is_flatnuke = true;

/*****************/


$modname = $_GET['mod'];
$myurl="index.php?mod=$modname";

if(isset($_GET['hop']))
	$hop=$_GET['hop'];
else
	$hop ="";

if(isset($_GET['hid']))
	$hid=$_GET['hid'];
else
	$hid ="";


function geturl($url){
	if ($url != "") {
		if (!ereg("http://",$url)) {
			$url = "http://$url";
		}
		$rdf = parse_url($url);
		$fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15);
		if (!$fp) {
			print(_NORSS);
			return;
		}
		if ($fp) {
			fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n");
			fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n");
			$string = "";
			while(!feof($fp)) {
				$pagetext = fgets($fp,228);
				$string .= chop($pagetext);
			}
			fputs($fp,"Connection: close\r\n\r\n");
			fclose($fp);
		}
	}
	return $string;
}


function get_news ($link) {
	global $theme;
	global $theme,$mesi,$giorni;
	global $fuso_orario;

	preg_match("/^(.*)\?.*$/", $link,$base);
	$url_news=str_replace("index.php","",$base[1]);
	$external_url = $url_news;

	preg_match("/^.*id=(\d+).*/", $link, $f1);
	$url_news= $url_news."/news/".$f1[1].".xml";
	$fd=(geturl($url_news));
	$news=$f1[1];

	$title=get_xml_element("fn:title",$fd);
	$avatar=get_xml_element("fn:avatar",$fd);
	$header=get_xml_element("fn:header",$fd);
	$body=get_xml_element("fn:body",$fd);
	$comments=get_xml_element("fn:comments",$fd);
	$comment=get_xml_array("fn:comment",$comments);

	OpenTableTitle("<img src=\"themes/$theme/images/read.png\" alt=\"Read\" />&nbsp;".$title);

	print stripslashes($header)."<br /><br />".stripslashes($body);

	print "<br /><br /><div align='center'><hr size='1' />";
	echo _POSTATO.$giorni[date("w",$news+(3600*$fuso_orario))].date(" d ",$news+(3600*$fuso_orario));
	$tmp=date("m",$news+(3600*$fuso_orario));
	if ($tmp<10)
		$tmp=str_replace("0","",$tmp);
	print $mesi[$tmp-1];
	echo date(" Y - ",$news+(3600*$fuso_orario)).date("H:",$news+(3600*$fuso_orario)).date("i",$news+(3600*$fuso_orario))."</div><br />";

	OpenTable();
	echo "<b>"._COMMENTI."</b> | <a href=\"$external_url/index.php?mod=comment&amp;id=$news\">"._ADDCOMM."</a> | <a href=\"$external_url/print.php?news=$news\" target=\"new\">"._STAMPA."</a>";
	CloseTable();

	for($j=0;$j<count($comment);$j++){
		print "<br />";
		OpenTable();
		$user=get_xml_element("fn:by",$comment[$j]);
		// autore del commento
		print "<b>"._DA."</b> $user  ";
		// data di inserzione del commento
		$date_comment = get_xml_element("fn:date",$comment[$j]);
		if(is_numeric($date_comment)){
			print "<b>"._DATA.":</b> ";
			echo $giorni[date("w",$date_comment+(3600*$fuso_orario))].date(" d ",$date_comment+(3600*$fuso_orario));
			$tmp_c = date("m",$date_comment+(3600*$fuso_orario));
			if ($tmp_c<10)
				$tmp_c = str_replace("0","",$tmp_c);
			print $mesi[$tmp_c-1];
			$date_comment = date(" Y - ",$date_comment+(3600*$fuso_orario)).date("H:",$date_comment+(3600*$fuso_orario)).date("i",$date_comment+(3600*$fuso_orario));
		}
		else $date_comment = "/";
		print "$date_comment<br /><br />";
		// contenuto del commento
		print stripslashes(get_xml_element("fn:post",$comment[$j]));
		CloseTable();
	}
	CloseTableTitle();
}

$rss = geturl($rss_file);


$url_topass="";

	$items = explode("</item>",$rss);
	$content = "<font class=\"content\">";
	for ($i=0;$i<sizeof($items)-1 ;$i++) {
		$link = ereg_replace(".*<link>","",$items[$i]);
		$link = ereg_replace("</link>.*","",$link);
		$title2 = ereg_replace(".*<title>","",$items[$i]);
		$title2 = ereg_replace("</title>.*","",$title2);
		if ($items[$i] == "" AND $cont != 1) {
			$content = "";
		} else {
			if (strcmp($link,$title2) AND $items[$i] != "") {
				$cont = 1;

				if(preg_match("/^.*id=(\d+).*/", $link, $f1)) {
					$id_news=$f1[1];
					if($id_news == $hid) {
						$url_topass = $link;
					}
				}
				else $id_news=0;

				if($is_flatnuke == true)
					$content .= "<strong><big>&middot;</big></strong>&nbsp;<a href=\"$link\" target=\"new\"><font class=\"content\">$title2</font></a> <a href=\"$myurl&amp;hop=read&amp;hid=$id_news\"><img src=\"themes/$theme/images/news.png\" border=\"0\" /></a><br />\n";
				else
					$content .= "<strong><big>&middot;</big></strong>&nbsp;<a href=\"$link\" target=\"new\"><font class=\"content\">$title2</font></a><br />\n";
			}
		}
	}

	if(($hop == "read") and ($hid!=0) and $is_flatnuke and ($url_topass != "")) {
		echo "<br />";
		echo get_news($url_topass);
		echo "<hr size=1 noshade /><br />";
	}

	echo $content;

?>
